<?php

namespace Drupal\shusy_store_order_line\Entity;

use Entity;

class ShusyStoreOrderLine extends Entity {

  public $id;

  public $vid;

  public $uid;

  public $op_uid;

  public $created;

  public $changed;

  public $is_new_revision;

  public $type;

  public $store_order_id;

  public $name;

  public $amount;

  public $amount_type = 0;

  public $spread_type = 0;

  public $spread_anchor_uid = 0;

  public $qty;

  public $total;

  public $status = 1;

  public $lid = 0;

  public $upTotal = TRUE;

  function __construct($values = []) {
    $this->is_new_revision = TRUE;
    parent::__construct($values, 'shusy_store_order_line');
  }

  public function save() {
    $this->changed = REQUEST_TIME;
    if (empty($this->created)) {
      $this->created = REQUEST_TIME;
    }

    $this->op_uid = $GLOBALS['user']->uid;
    if (empty($this->uid)) {
      $this->uid = $GLOBALS['user']->uid;
    }
    if ($this->upTotal) {
      //保存的时候计算总价
      $this->total = $this->qty * $this->amount;
    }
    return parent::save();
  }

}
